package be.florent.brol.client.activities;

import be.credoc.common.gwt.actions.client.OnResponseCommand;
import be.florent.brol.client.ClientFactory;
import be.florent.brol.client.mvp.MyView;
import be.florent.brol.client.places.MyPlace;
import be.florent.brol.shared.actions.GetGreetingA;
import be.florent.brol.shared.actions.GetGreetingR;

import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.AcceptsOneWidget;

public class MyActivity extends AbstractActivity implements MyView.Presenter {

	private ClientFactory clientFactory;
	private MyPlace place;
	private MyView view;

	public MyActivity(MyPlace place, ClientFactory clientFactory) {
		this.place = place;
		this.clientFactory = clientFactory;
	}

	@Override
	public void start(AcceptsOneWidget panel, EventBus eventBus) {
		view = clientFactory.getMyView();
		view.setPresenter(this);
		panel.setWidget(view.asWidget());
	}

	@Override
	public void sendButtonClicked() {
		clientFactory.getActionServiceWrapper().execute(
				new GetGreetingA<GetGreetingR>(view.getName()),
				new OnResponseCommand<GetGreetingR>() {
					@Override
					public void execute() {
						view.setGreetingMessage(response.getGreeting());
					}
				}
				);
	}

}
